<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script src="../dev/vendors/vue.js"></script>
  <div id="app">
    组件A
    <my-a></my-a>
    组件B
    <my-b></my-b>
  </div>
  <script>
    var bus = new Vue()
    //my-a
    Vue.component('my-a', {
      template: '<div><input v-model="msg"></div>',
      data: function () {
        return {
          msg: ''
        }
      },
      watch: {
        msg: function (value) {
          bus.$emit('modify-b', value)
        }
      }
    })
    //my-b
    Vue.component('my-b', {
      template: '<div>{{ text }}</div>',
      created: function () {
        var _this = this
        bus.$on('modify-b', function (value) {
          _this.text = value
        })
      },
      data: function () {
        return {
          text: '456'
        }
      }
    })
    //app
    var vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>